<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
 * Description of category_model
 *
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Admin_review_model extends CI_Model {

	//put your code here


	function __construct() {
		parent::__construct();
		log_message('debug', 'Init Model Initialized');
	}

	//-- Get listings(Multi Row) --//
	/*function get_reviews($featured = false, $status = 1,  $num=NULL, $offset = NULL) {
		
			if ($featured == false) {
				$sql = "Select * from review_master where status=$status order by id desc limit $num, $offset ";
			} else {
				$sql = "Select * from review_master where featured =1 and status=$status order by id desc limit $num, $offset";
			}
			$query = $this->db->query($sql);
			return $query->result();
		
	}
	*/
	function get_reviews($featured=false, $status=1,$num=NULL, $offset=NULL) {
		$subcond = "where status=$status";
		$limit = "";
		if (isset($num) && isset($offset))
			$limit = " order by (id) desc limit $offset, $num";
		$sql = "select * from review_master " . $subcond . $limit;
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}
	
	function get_inactive_reviews($featured=false, $status=51,$num=NULL, $offset=NULL) {
		$subcond = "where status=$status";
		$limit = "";
		if (isset($num) && isset($offset))
			$limit = " order by (id) desc limit $offset, $num";
		$sql = "select * from review_master " . $subcond . $limit;
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}
	
	function search($search=null){
		$sql = "Select * from review_master where name like '%$search%' order by id desc";
		$query = $this->db->query($sql);
		$result = $query->result();
		if($result){
			return $query->result();
		}else{
			return false;
		}
	
	
	}
	
	function get_review($id=NULL)
	{
	$sql = "Select * from review_master where id= $id and status=51";
	$query = $this->db->query($sql);
	$row = $query->row();
	return $row; 	
	}
	/*
	function change_status($status=NUll, $id=NULL)
	{
	
		$sql="update review_master set status=$status where id=$id";
		$this->db->query($sql);
	}
	*/
	function change_status($id, $status) {
		if ($status == 1) {
			$sql = "update review_master set status=51 where id=$id";
		}
		if ($status == 51) {
			$sql = "update review_master set status=1 where id=$id";
		}
		$this->db->query($sql);
	}
	
	
	function delete($id=NULL)
	{
		$sql="delete from review_master where id=$id";
		$this->db->query($sql);
	}
}